<?php
namespace app\lib\yiyan;

class Yiyan
{
    protected $appId = "38514601";
    protected $apiKey = 'Og9xyLAiEB5F6GcMhpSfAPiT';
    protected $secretKey = 'AjU7dKAfbLm3DGKf37ImIr8c2eTP8pvM';

    public function getAccessToken(){
        $url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$this->apiKey
            ."&client_secret=".$this->secretKey;
        $head = array(
            'Content-Type: application/json'
        );
        $response = curlGet($url,$head);
        return json_decode($response);

    }
    public function turbo($question)
    {
        $access_token = "24.89ab6caef7d86bdf4f9dcc5e4c078735.2592000.1718783872.282335-38514601";
        $headerss = array(
            'Content-Type: application/json'
        );
        $data = [
            "messages" => []
        ];

        $data['messages'][0] = ["role"=> "user","content" => $question];
        $data = json_encode($data);
        $response = curlPost('https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/eb-instant?access_token='.$access_token,$data,$headerss);


        return $response;

    }

    public function studyText($title){
        $promot = "我希望你是个资深教育这，围绕'".$title."'这个话题展开描述，字数不超过30";
        $response = $this->turbo($promot);
        return $response;
    }

    public function derivativeWork($title,$body,$comment){
        $promot = "有一篇标题为".$title."的文章，文章的内容是：".$body."。这篇文章底下有个评论，评论内容是：'".$comment."';能不能结合评论内容提炼文章，文章字数要高于320字并且不超过500字，语句要有感染力且不能重复。";
        $response = $this->turbo($promot);
        return $response;
    }

    public function model($content){
        $promot = "标题:xxxx,xxxx,xxxxx 主题：xxx 小标题：xxxxxx 内容：xxxxx 小标题：xxxxxx 内容：xxxxx 小标题：xxxxxx 内容：xxxxx; 按照以上格式改写内容：" . $content;

        $response = $this->turbo($promot);
        return $response;
    }






}
